import { Entity, Column } from "typeorm";

import type { VARCHAR50_PG, INTEGER_PG, VARCHAR255_PG } from "qqlx-core";
import { ENUM_PAYMENT, PaymentWeChatMp, PaymentWeChatMpGateway, ENUM_PAYMENT_WECHAT_MP_TYPE, ENUM_PAYMENT_WECHAT_MP_STATE } from "qqlx-core";

import { TransformerInteger } from "@lib/orm.transfor.number";
import { TransformerVarchar50 } from "@lib/orm.transfor.string";
import { TransformerEnum, TransformerEnumStr } from "@lib/orm.transfor.enum";

import { OwnerIdSchema } from "@/alpha/ext.id.base";

@Entity({ name: PaymentWeChatMpGateway.relations })
export class PaymentWeChatMpSchema extends OwnerIdSchema implements PaymentWeChatMp {
  @Column({ transformer: new TransformerEnum(Object.values(ENUM_PAYMENT), ENUM_PAYMENT.NONE) })
  type: ENUM_PAYMENT = ENUM_PAYMENT.NONE;

  @Column({ transformer: new TransformerInteger() })
  amount: INTEGER_PG = 0;

  @Column({ transformer: new TransformerVarchar50() })
  orderId: VARCHAR50_PG = "";

  @Column({ transformer: new TransformerVarchar50() })
  wxTradeId: VARCHAR50_PG = "";

  @Column({ transformer: new TransformerEnumStr(Object.values(ENUM_PAYMENT_WECHAT_MP_STATE), ENUM_PAYMENT_WECHAT_MP_STATE.NONE) })
  wxTradeType: ENUM_PAYMENT_WECHAT_MP_TYPE = ENUM_PAYMENT_WECHAT_MP_TYPE.NONE;

  @Column({ transformer: new TransformerEnumStr(Object.values(ENUM_PAYMENT_WECHAT_MP_STATE), ENUM_PAYMENT_WECHAT_MP_STATE.NONE) })
  wxTradeState: ENUM_PAYMENT_WECHAT_MP_STATE = ENUM_PAYMENT_WECHAT_MP_STATE.NONE;

  @Column({ transformer: new TransformerVarchar50() })
  wxTradeStateDesc: VARCHAR50_PG = "";

  @Column({ transformer: new TransformerVarchar50() })
  wxTradeQRCode: VARCHAR255_PG = "";
}
